<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Bar;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BarController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Bar(), function (Grid $grid) {
            $grid->actions(function (Grid\Displayers\Actions $actions) {
//                $actions->disableDelete();
//                $actions->disableEdit();
                $actions->disableQuickEdit();
                $actions->disableView();
            });
            $grid->column('bar_id','ID')->sortable();
            $grid->column('bar_name')->tree(true); // 开启树状表格功能;
            $grid->column('bar_sort');
            $grid->column('status');
//            $grid->column('bar_url');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('bar_id');

            });
        });
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Bar(), function (Form $form) {
            $form->display('bar_id');
            $data = [0=>'顶级分类'] + \App\Models\Bar::all()->where('parent_id','=',0)
                    ->pluck('bar_name','bar_id')->toArray();
            $form->select('parent_id')->options($data);
            $form->text('bar_name');
            $form->text('bar_sort');
//            $form->text('bar_url');

            $form->display('created_at');
            $form->display('updated_at');
            $form->saved(function (Form $form) {
                return $form->response()->success('保存成功')->redirect('bar');
            });
            $form->footer(function ($footer) {

                // 去掉`重置`按钮
                //$footer->disableReset();

                // 去掉`提交`按钮
                //$footer->disableSubmit();

                // 去掉`查看`checkbox
                $footer->disableViewCheck();

                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();

                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
        });
    }
}
